$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'cgs/cgsappeal/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true,hidden:true },
			{ label: '', name: 'applyUserId', index: 'apply_user_id', width: 80,hidden:true },
			{ label: '申请用户', name: 'applyUserName', index: 'apply_user_name', width: 80,hidden:true },
			{ label: '', name: 'idCardNum', index: 'id_card_num', width: 80,hidden:true },
			{ label: '联系方式', name: 'mobile', index: 'mobile', width: 80,hidden:true },
			{ label: '', name: 'address', index: 'address', width: 80,hidden:true },
			{ label: '诉求内容', name: 'appealContent', index: 'appeal_content', width: 80 },
			{ label: '诉求时间', name: 'appealTime', index: 'appeal_time', width: 80 },
			{ label: '办理状态', name: 'status', index: 'status', width: 80,formatter:function(value,options,row){
                return dictJudge(value, vm.status);
            } },
			{ label: '受理时间', name: 'acceptTime', index: 'accept_time', width: 80 },
			{ label: '不受理原因', name: 'notAcceptReason', index: 'not_accept_reason', width: 80 },
			{ label: '', name: 'leaderHandleTime', index: 'leader_handle_time', width: 80,hidden:true },
			{ label: '', name: 'leaderFeedback', index: 'leader_feedback', width: 80,hidden:true },
			{ label: '', name: 'leaderFeedbakImg', index: 'leader_feedbak_img', width: 80,hidden:true },
			{ label: '', name: 'handleDeadline', index: 'handle_deadline', width: 80,hidden:true },
			{ label: '车管所', name: 'cgsId', index: 'cgs_id', width: 80,formatter:function(value,options,rows){
                return dictJudge(value, vm.cgs);
            } },
			{ label: '车管所反馈', name: 'cgsFeedback', index: 'cgs_feedback', width: 80 },
			{ label: '', name: 'cgsFeedbackImg', index: 'cgs_feedback_img', width: 80,hidden:true },
			{ label: '', name: 'cgsHandleTime', index: 'cgs_handle_time', width: 80,hidden:true },
			{ label: '', name: 'createTime', index: 'create_time', width: 80,hidden:true }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		cgsAppeal: {},
        cgs:[],
        appealStatus:[],
        shenpi:{}
	},
    created:function(){
        $.get(baseURL+"/sys/dict/select/cgs,appealStatus",function (data) {
            vm.cgs = data.dict.cgs;
            vm.status = data.dict.appealStatus;
        });
    },
	methods: {
		query: function () {
			vm.reload();
		},
        look: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "详情/办理";
            
            vm.getInfo(id)
		},
        executeAudit: function (event) {
			var url =  "cgs/cgsappeal/update";
			if(!vm.shenpi.status){
                alert("请选择审理结果");
                return ;
            }
            if((vm.shenpi.status === '3' && !vm.shenpi.cgsFeedback )
                || (vm.shenpi.status === '6' && !vm.shenpi.leaderFeedback)) {
                alert("请填写事由");
                return ;
            }
            vm.shenpi.id = vm.cgsAppeal.id;
			if(vm.cgsAppeal.status === '2') {
                vm.shenpi.leaderHandleTime = dateFtt('yyyy-MM-dd hh:mm:ss', new Date());
            }else if(vm.cgsAppeal.status === '1') {
                vm.shenpi.cgsHandleTime = dateFtt('yyyy-MM-dd hh:mm:ss', new Date());
            }
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.shenpi),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
							$("#cgscheckModal").modal("hide")
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
        banjie:function(){
		    vm.shenpi.status = '5';
		    vm.shenpi.id = vm.cgsAppeal.id;
            $.ajax({
                type: "POST",
                url: baseURL + "cgs/cgsappeal/update",
                contentType: "application/json",
                data: JSON.stringify(vm.shenpi),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "cgs/cgsappeal/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "cgs/cgsappeal/info/"+id, function(r){
                vm.cgsAppeal = r.cgsAppeal;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});